#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
HDF5文件快速查看器
快速显示HDF5文件的基本结构和数据信息
"""

import h5py
import numpy as np
import os
import sys

def print_structure(name, obj, indent=0):
    """递归打印HDF5结构"""
    prefix = "  " * indent
    
    if isinstance(obj, h5py.Group):
        print(f"{prefix}📁 {name}/ (组)")
        print(f"{prefix}   └─ 包含 {len(obj)} 个子项")
        for key in obj.keys():
            print_structure(key, obj[key], indent + 1)
    
    elif isinstance(obj, h5py.Dataset):
        print(f"{prefix}📄 {name} (数据集)")
        print(f"{prefix}   ├─ 形状: {obj.shape}")
        print(f"{prefix}   ├─ 类型: {obj.dtype}")
        print(f"{prefix}   └─ 大小: {obj.nbytes / (1024*1024):.2f} MB")

def main():
    filepath = "DAQ_h5/CM01_01_data_20250611_09_18_57.h5"
    
    if len(sys.argv) > 1:
        filepath = sys.argv[1]
    
    print("=" * 50)
    print("🔍 HDF5文件结构快速查看")
    print("=" * 50)
    print(f"📂 文件: {filepath}")
    print(f"📏 大小: {os.path.getsize(filepath) / (1024*1024):.2f} MB")
    print("-" * 50)
    
    try:
        with h5py.File(filepath, 'r') as f:
            print(f"🏷️  根目录包含 {len(f)} 个组")
            print()
            
            for key in f.keys():
                print_structure(key, f[key])
                print()
            
    except Exception as e:
        print(f"❌ 错误: {e}")
    
    print("=" * 50)

if __name__ == "__main__":
    main() 